﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using ColorProgressBar;

namespace NutriFast
{
    public partial class DietaSelRes : Form
    {
        public DietaSelRes()
        {
            InitializeComponent();
        }

        private void DietaSelRes_Load(object sender, EventArgs e)
        {
            textBox2_TextChanged(null, null);

            listAlimentos.Clear();
            listTodos.Clear();
            llenarlista("");

        }

        private void llenarlista(string filtro)
        {
            DataTable dt = dbTavo.searchFood(filtro);

            // Suspending automatic refreshes as items are added/removed.
            listTodos.BeginUpdate();

            listTodos.LargeImageList = imagesLarge;
            foreach (DataRow dr in dt.Rows)
            {

                ListViewItem listItem = new ListViewItem(dr["fName"].ToString());
                if (int.Parse(dr["fGroup"].ToString()) == 1)
                {
                    listItem.ImageIndex = 0;
                }
                if (int.Parse(dr["fGroup"].ToString()) == 2)
                {
                    listItem.ImageIndex = 1;
                }
                if (int.Parse(dr["fGroup"].ToString()) == 3)
                {
                    listItem.ImageIndex = 2;
                }
                if (int.Parse(dr["fGroup"].ToString()) == 4)
                {
                    listItem.ImageIndex = 3;
                }

                // Add sub-items for Details view.
                listItem.SubItems.Add(dr["csugerida"].ToString());
                listItem.SubItems.Add(dr["unidad"].ToString());
                listItem.SubItems.Add(dr["kcal"].ToString());
                 

                listTodos.Items.Add(listItem);
            }

            // Add column headers for Details view.
            listTodos.Columns.Add("Nombre", 140, HorizontalAlignment.Center);
            listTodos.Columns.Add("Cantidad", 60, HorizontalAlignment.Center);
            listTodos.Columns.Add("Unidad", 60, HorizontalAlignment.Center);
            listTodos.Columns.Add("Kcal", 40, HorizontalAlignment.Center);

            // Re-enable the display.
            listTodos.EndUpdate();

        }

        private void NewView(object sender, System.EventArgs e)
        {

            listTodos.View = (View)(((Control)sender).Tag);
            //this.Text = "Using View: " + listTodos.View.ToString();
        }

        private void optLargeIcon_Click(object sender, EventArgs e)
        {
            listTodos.View = System.Windows.Forms.View.LargeIcon;
        }

        private void optDetails_Click(object sender, EventArgs e)
        {
            listTodos.View = System.Windows.Forms.View.Details;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            for (int k = 0; k < listTodos.SelectedIndices.Count; k++)
            {
                ListViewItem lvi = listTodos.Items[listTodos.SelectedIndices[k]];
                gFood.Rows.Add(lvi.Text);
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                this.spPeriquinBuscarRecetaTableAdapter.Fill(this.dsBuscarReceta.spPeriquinBuscarReceta, textBox2.Text);

            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }



        private void g100_SelectionChanged(object sender, EventArgs e)
        {
            if (g100.Rows.Count >= 1)
            {
                try
                {
                    this.spPeriquinRecetaIngredientesTableAdapter.Fill(this.dsRecetaIngredientes.spPeriquinRecetaIngredientes, int.Parse(g100.Rows[g100.CurrentRow.Index].Cells[0].Value.ToString()));
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }

        }



        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            listTodos.Clear();
            llenarlista(textBox1.Text);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (gFood.Rows.Count != 0)
            {

                int index = gFood.CurrentRow.Index;
                gFood.Rows.RemoveAt(index);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
        }


        
    }
}
